package com.cwhuang.g7_tool_myhymns;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.os.Environment;
import android.widget.Toast;
import au.com.bytecode.opencsv.CSVReader;

/**
 * @author G7
 *	專門處理app內外資料讀取與存入，讓各activity在pause或stop時把重要資訊存入硬碟
 */
public class HymnsIO {
	public final static String COL_SERIAL = "col_serial";
	public final static String COL_INDEX = "col_index";
	public final static String COL_TITLE = "col_title";
	public final static String COL_RATING = "col_rating";
	public final static String COL_TIMES = "col_times";
	public final static String COL_FAMILIARITY = "col_familiarity";
	public final static String COL_STYLES = "col_style";
	public final static String COL_OCCASIONS = "col_occasions";
	public final static String COL_PIANO_DIFFICULTY = "col_piano_difficulty";
	public final static String COL_PIANO_FAMILIARITY = "col_piano_familiarity";
	public final static String COL_MELODY_COMPOSER = "col_melody_composer";
	public final static String COL_LYRIC_WRITTER = "col_lyric_writter";
	public final static String COL_LYRIC = "col_lyric";
	public final static String COL_ALBUMS = "col_albums";
	public final static String COL_TONALITY = "col_tonality";
	public final static String COL_TEMPO = "col_tempo";
	public final static String COL_VERSE = "col_verse";
	public final static String COL_STORY= "col_story";
	public final static String COL_MELODY = "col_melody";
	public final static String COL_HYMN_EVENTS = "col_hymn_events";
	
	private String fpath = "/MyHymns";
	private String fname = "hymns.csv";
	AppHymns myHymns;
	
    public void loadHymns(Context context){
    	myHymns = (AppHymns)context.getApplicationContext();
    	myHymns.hymns = new ArrayList<Map<String,Object>>();
    	File file;
    	
    	//TODO 考慮做選項，讓大家選要把hymns.csv存在哪裡；然後寫一個能存在內存SD卡的方法
    	
    	//測試SD卡
    	if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
    		Toast.makeText(context, "沒有SD卡的樣子", Toast.LENGTH_SHORT).show();
    		return;
    	}
    	//在SD卡建立及讀取檔案
    	try{
    		//找到我們的資料夾與檔案名稱
    		File sd = Environment.getExternalStorageDirectory();
    		File dir = new File(sd.getAbsolutePath()+fpath);
    		file = new File(dir, fname);

    		//去尋找檔案如果不存在，就自動輸出一個完整的hymns.csv資料庫
    		if(!dir.exists()){
    			dir.mkdir();
    			createHymns(file);
    		}
    		if(!file.exists()){
    			createHymns(file);
    		}
    	
    		//讀取檔案
    		FileInputStream fileInputStream = new FileInputStream(file);
    			//編碼問題：用big5此編碼去讀檔案，才可顯示中文字
    		InputStreamReader inputStreamReader = 
    				new InputStreamReader(fileInputStream, "BIG5");
    		BufferedReader bufReader = new BufferedReader(inputStreamReader);

    		CSVReader csvReader = new CSVReader(bufReader);
			String [] results;
		    while ((results = csvReader.readNext()) != null) {
		    	
//		    	for(int i=0; i<results.length; i++){
//		    		Log.d("看一下results", "i: "+i +"  "+ results[i]);
//		    	}
		    	
		    	//如果讀到的是header，就直接跳過
		    	if(results[0].equals("資料庫序列") ){
		    		continue;
		    	}
		    	
		    	//先把不一定抓到的的項目歸零：為了避免讀取時的nullPointerException
		    	HashMap<String, Object> hMap = myHymns.addDefaultHymn();
    			//再開始納入檔案
    			hMap.put(COL_SERIAL, results[0]);
    			hMap.put(COL_INDEX, results[1]);
    			hMap.put(COL_TITLE, results[2]);
				hMap.put(COL_RATING, results[3]);
				hMap.put(COL_TIMES, results[4]);
				hMap.put(COL_FAMILIARITY, results[5]);
				
				//對於那些只有最基本資料的hymns.csv來說，一定要有這個
				if (results.length > 6 ) {
						ArrayList<String> styles = new ArrayList<String>();
						for(String style : results[6].split(",") ){
							styles.add(style);
						}
					hMap.put(COL_STYLES, styles);
						ArrayList<String> occasions = new ArrayList<String>();
						for(String occasion : results[7].split(",") ){
							occasions.add(occasion);
						}
	    			hMap.put(COL_OCCASIONS, occasions);
	    			hMap.put(COL_PIANO_DIFFICULTY, results[8]);
	    			hMap.put(COL_PIANO_FAMILIARITY, results[9]);
	    			hMap.put(COL_MELODY_COMPOSER, results[10]);
	    			hMap.put(COL_LYRIC_WRITTER, results[11]);
	    			hMap.put(COL_MELODY, results[12]);
	    			hMap.put(COL_LYRIC, results[13]);
	    			hMap.put(COL_ALBUMS, results[14]);
	    			hMap.put(COL_TONALITY, results[15]);
	    			hMap.put(COL_TEMPO, results[16]);
	    			hMap.put(COL_VERSE, results[17]);
	    			hMap.put(COL_STORY, results[18]);
		    			ArrayList<String> hymnEvents = new ArrayList<String>();
						for(String hymnEvent : results[19].split(",") ){
							hymnEvents.add(hymnEvent);
						}
	    			hMap.put(COL_HYMN_EVENTS, hymnEvents);	
				}	//End if > 最基本資料
				
				myHymns.hymns.add(hMap);
		    }	//END while
    		
		    csvReader.close();
            bufReader.close();
    		inputStreamReader.close();
    	}catch(IOException exception){
    		exception.printStackTrace();
    	}
    }	//end loadHymns()
    
    public void saveHymns(Context context){
    	myHymns = (AppHymns)context.getApplicationContext();
    	File file;
    	
    	//在SD卡建立及讀取檔案
    	try{
    		//找到我們的資料夾與檔案名稱
    		File sd = Environment.getExternalStorageDirectory();
    		File dir = new File(sd.getAbsolutePath()+fpath);
    		file = new File(dir, fname);

    		FileOutputStream out = new FileOutputStream(file);
    		OutputStreamWriter sw = new OutputStreamWriter(out, "BIG5");
    		
    		//把header寫入
    		sw.write("資料庫序列,編目,歌名,評等,編輯次數,熟悉度," +
    				"風格,場合,司琴難易度,司琴熟練度,作曲者,作詞者,歌譜," +
    				"歌詞,詩集,調性,節奏,經節,故事,詩歌事件\r\n");
    		for(int i=0;i<myHymns.hymns.size();i++){
    			String str ="";
    			String comma = ",";
    			String serial = myHymns.hymns.get(i).get(COL_SERIAL).toString();
    			String index = myHymns.hymns.get(i).get(COL_INDEX).toString();
    			String title = myHymns.hymns.get(i).get(COL_TITLE).toString();
    			String rating = myHymns.hymns.get(i).get(COL_RATING).toString();
    			String times = myHymns.hymns.get(i).get(COL_TIMES).toString();
    			String familiarity = myHymns.hymns.get(i).get(COL_FAMILIARITY).toString();
    			String style = "";
	    			@SuppressWarnings("unchecked")
					ArrayList<String> styles = (ArrayList<String>) myHymns.hymns.get(i).get(COL_STYLES);
	    			for (int j=0; j<styles.size(); j++){
	    				if(j==0){ style += styles.get(0); }
	    				else{	style += "," + styles.get(j);	}
	    			}
    			String occassion = "";
	    			@SuppressWarnings("unchecked")
					ArrayList<String> occassions = (ArrayList<String>) myHymns.hymns.get(i).get(COL_OCCASIONS);
	    			for (int j=0; j<occassions.size(); j++){
	    				if(j==0){ occassion += occassions.get(0); }
	    				else{	occassion+= "," + occassions.get(j);	}
	    			}
    			String piano_difficulty = myHymns.hymns.get(i).get(COL_PIANO_DIFFICULTY).toString(); 
    			String piano_familiarity = myHymns.hymns.get(i).get(COL_PIANO_FAMILIARITY).toString(); 
    			String melody_composer = myHymns.hymns.get(i).get( COL_MELODY_COMPOSER).toString(); 
    			String lyric_writter = myHymns.hymns.get(i).get(COL_LYRIC_WRITTER ).toString(); 
    			String melody = myHymns.hymns.get(i).get( COL_MELODY).toString(); 
    			String lyric = myHymns.hymns.get(i).get( COL_LYRIC).toString(); 
    			String album = myHymns.hymns.get(i).get( COL_ALBUMS).toString(); 
    			String tonality = myHymns.hymns.get(i).get( COL_TONALITY).toString(); 
    			String tempo = myHymns.hymns.get(i).get( COL_TEMPO).toString(); 
    			String verse = myHymns.hymns.get(i).get( COL_VERSE).toString(); 
    			String story = myHymns.hymns.get(i).get( COL_STORY).toString();
    			String hymn_event = "";
	    			@SuppressWarnings("unchecked")
					ArrayList<String> hymn_events = (ArrayList<String>) myHymns.hymns.get(i).get(COL_HYMN_EVENTS);
	    			for (int j=0; j<hymn_events.size(); j++){
	    				if(j==0){ hymn_event += hymn_events.get(0); }
	    				else{	hymn_event+= "," + hymn_events.get(j);	}
	    			}
	    			
    			//對於字串的項目，頭尾要加上" "
    			str = serial+ comma+index+comma+title+comma+rating+comma+times+comma
    						+ familiarity+comma+ "\""+ style + "\""+comma
    						+ "\""+ occassion + "\"" + comma + piano_difficulty + comma
    						+ piano_familiarity + comma + melody_composer + comma 
    						+ lyric_writter + comma + melody + comma + lyric + comma
    						+ album + comma + tonality + comma + tempo + comma + verse + comma
    						+ story +comma + "\""+ hymn_event + "\"";
    			sw.write(str + "\r\n");  
    		}
    		sw.flush();     
    		sw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}	//END try
    }	//END saveHymns()
    
    public void createHymns(File file){
    	//把hymns.csv的檔案內容複製貼上到這裡
    	//把它設為一行一行的string，每個項目內容中間要有,隔開
    	//再寫入進去hymns.csv
    	String lineString = "";
    	final int TOTAL_NUMBER = 472; 
    	int[] serial = new int[TOTAL_NUMBER];
    	for(int i=0;i<serial.length;i++){
    		serial[i] = i+1;
    	}
    	int[] index = new int[]{
    		1	,2	,3	,4	,5	,6	,7	,8	,9	,10	,
    		11	,12	,13	,14	,15	,16	,17	,18	,19	,20	,
    		21	,22	,23	,24	,25	,26	,27	,28	,29	,30	,
    		31	,32	,33	,34	,35	,36	,37	,38	,39	,40	,
    		41	,42	,43	,44	,45	,46	,47	,48	,49	,50	,
    		51	,51	,52	,53	,54	,55	,56	,57	,58	,59	,
    		60	,61	,62	,63	,64	,65	,66	,67	,68	,69	,
    		70	,71	,72	,73	,74	,75	,76	,77	,78	,79	,
    		80	,81	,82	,83	,84	,85	,86	,87	,88	,89	,
    		90	,91	,92	,93	,94	,95	,96	,97	,98	,99	,
    		100	,101,102,103,104,105,106,107,108,109,110,
    		111	,112,113	,114	,115	,
    		116	,117	,118	,119	,120	,
    		121	,122	,123	,124	,124	,
    		125	,126	,127	,128	,129	,
    		130	,131	,132	,133	,134	,
    		135	,136	,137	,138	,139	,
    		140	,141	,142	,143	,144	,
    		145	,146	,147	,148	,149	,
    		150	,151	,152	,153	,154	,
    		155	,156	,157	,158	,159	,
    		160	,161	,162	,163	,164	,
    		165	,166	,167	,168	,169	,
    		170	,171	,172	,173	,174	,
    		175	,176	,177	,178	,179	,
    		180	,181	,182	,183	,184	,
    		185	,186	,187	,188	,189	,
    		190	,191	,192	,193	,194	,
    		195	,196	,197	,198	,199	,
    		200	,201	,202	,203	,204	,
    		205	,206	,207	,208	,209	,
    		210	,211	,212	,213	,214	,
    		215	,216	,217	,218	,219	,
    		220	,221	,222	,223	,224	,
    		225	,226	,227	,228	,229	,
    		230	,231	,232	,233	,234	,
    		235	,236	,237	,238	,239	,
    		240	,241	,242	,243	,244	,
    		245	,246	,247	,248	,249	,
    		250	,251	,252	,253	,254	,
    		255	,256	,257	,258	,259	,
    		260	,261	,262	,263	,264	,
    		265	,266	,267	,268	,269	,
    		270	,271	,272	,273	,274	,
    		274	,275	,276	,277	,278	,279	,280	,281	,
    		282	,283	,284	,285	,286	,287	,288	,
    		289	,290	,291	,292	,293	,294	,
    		295	,296	,296	,297	,298	,299	,300	,301	,
    		302	,303	,304	,305	,306	,307	,308	,309	,
    		310	,311	,312	,313	,314	,315	,316	,317	,
    		318	,319	,320	,321	,322	,323	,324	,325	,
    		326	,327	,328	,329	,330	,331	,332	,333	,
    		334	,335	,336	,337	,338	,339	,340	,341	,
    		342	,343	,344	,345	,346	,347	,348	,349	,
    		350	,351	,352	,353	,354	,355	,356	,357	,
    		358	,359	,360	,361	,362	,363	,364	,365	,
    		366	,367	,368	,369	,370	,371	,372	,373	,
    		374	,375	,376	,377	,378	,379	,380	,381	,
    		382	,383	,384	,385	,386	,387	,388	,389	,
    		390	,391	,392	,393	,394	,395	,396	,397	,
    		398	,399	,400	,401	,402	,403	,404	,405	,
    		406	,407	,408	,409	,410	,411	,412	,413	,
    		414	,415	,416	,417	,418	,419	,420	,421	,
    		422	,423	,424	,425	,426	,427	,428	,429	,
    		430	,431	,432	,433	,434	,435	,436	,437	,
    		438	,439	,440	,441	,442	,443	,444	,445	,
    		446	,447	,448	,449	,450	,451	,452	,453	,
    		454	,455	,456	,457	,458	,459	,460	,461	,
    		462	,463	,464	,465	,466	,467	,468	
    		};
    	String[] title = new String[]{
    			"頌讚獨一真神",
    			"讚美聖父",
    			"亞伯拉罕的神",
    			"讚美天父",
    			"萬有讚美天父",
    			"頌主造化大功",
    			"萬有齊頌主",
    			"當向神歌頌",
    			"向主歡呼",
    			"榮耀歸耶穌",
    			"在主內頂快樂",
    			"耶穌尊名",
    			"無人能比耶穌",
    			"萬王之王",
    			"頌讚耶穌",
    			"敬拜天地主宰",
    			"頌讚主慈愛",
    			"歌頌主恩",
    			"和散那",
    			"尊主為王",
    			"美哉，主耶穌！",
    			"讚美經訓",
    			"聖經寶貴",
    			"生命之道",
    			"神言純潔寶貴",
    			"求主向我發言",
    			"耶穌愛我",
    			"耶穌仁愛",
    			"主尋亡羊",
    			"妙愛找我",
    			"主全為我",
    			"耶穌肯收納罪人",
    			"到新耶路撒冷",
    			"耶穌恩召",
    			"雨夜後見光明",
    			"微聲盼望",
    			"硃紅罪變如雪",
    			"我聞耶穌呼聲",
    			"惟獨主血有效",
    			"主之寶血",
    			"主血有權能",
    			"羔羊寶血",
    			"寶血洗淨",
    			"惟有主能救我",
    			"搭救罪人",
    			"主開心眼",
    			"耶穌救我",
    			"救恩成在十字架",
    			"主拯救我",
    			"惟獨耶穌",
    			"萬古靈磐(甲)",
    			"萬古靈磐(乙)",
    			"主恩浩大",
    			"天父慈仁",
    			"離暗就光",
    			"蒙主釋放",
    			"禧年已到",
    			"我罪極罪",
    			"耶穌領我",
    			"求主引導",
    			"行走天路",
    			"求主引路",
    			"願主偕行",
    			"願主領路",
    			"真光領導",
    			"靠近主",
    			"主，我等候你！",
    			"求主指引我路",
    			"求主攜我手",
    			"求主操我舵",
    			"主有萬福",
    			"耶穌我主",
    			"萬福之主",
    			"賜福救主",
    			"救主降生",
    			"基督降生",
    			"耶穌受死",
    			"高舉十架",
    			"樂主復活",
    			"耶穌復活頌",
    			"主已戰勝死亡",
    			"耶穌再臨",
    			"儆醒預備",
    			"耶穌來時",
    			"歡迎我王",
    			"主快再來",
    			"善惡有報",
    			"審判大日",
    			"救主恩功",
    			"主恩更多",
    			"數算恩典",
    			"想念主愛",
    			"病癒感恩",
    			"更新感恩",
    			"主恩長存",
    			"受膏的君王",
    			"奇異恩典",
    			"我主離開象牙宮",
    			"當我思量十架",
    			"愛主更深",
    			"捨己為主",
    			"專愛耶穌",
    			"為主而活",
    			"快親近神",
    			"深愛耶穌",
    			"為主捨命",
    			"我是耶穌門徒",
    			"容我與主同行",
    			"跟從救主",
    			"踐主跡行",
    			"撇物從主",
    			"跟隨救主",
    			"我跟隨主",
    			"奉獻會堂",
    			"感恩奉獻",
    			"會堂落成",
    			"獻上身心",
    			"奉獻祈納",
    			"奉獻全生",
    			"都歸耶穌我救主",
    			"奉獻所有",
    			"我獻何物給耶穌？",
    			"彼此相愛",
    			"聖徒送行",
    			"實行愛心?(甲)",
    			"實行愛心?(乙)",
    			"別離詩",
    			"兄弟相愛",
    			"切實相愛",
    			"快樂聖日",
    			"記念聖日",
    			"安息聖日",
    			"樂守聖日",
    			"求主蔭庇",
    			"耶穌不改變",
    			"仰望救主",
    			"為甚麼忙",
    			"我知所信的是誰",
    			"主是我良友",
    			"我所信有根基",
    			"聞主過路",
    			"救主明白你的憂傷",
    			"永樂或永苦",
    			"靠主消除憂傷",
    			"我要投靠主",
    			"專心仰賴主",
    			"依靠耶穌",
    			"時刻靠主",
    			"先求神國神義",
    			"耶穌牧我",
    			"安息在膀臂中",
    			"善牧看顧",
    			"天父必看顧你",
    			"主必預備",
    			"時刻交託主",
    			"耶穌我堅固保障",
    			"主常看顧我",
    			"與主同行",
    			"神國在心",
    			"走在主路上",
    			"主賜真平安",
    			"真光在心",
    			"在主蔭下",
    			"主負我重擔",
    			"我靈魂永安樂",
    			"主恩夠用",
    			"耶穌懷抱我",
    			"在主蔭庇之下",
    			"十架精兵",
    			"精兵前進",
    			"善惡有報",
    			"為主勇往",
    			"教會惟一根基",
    			"你該得勝",
    			"十架旌旗",
    			"真教會必興起",
    			"百折不回",
    			"常常有勝利",
    			"切莫順從誘惑",
    			"趁還有今天",
    			"預備進天國",
    			"永生門路",
    			"我必前進",
    			"往前走",
    			"勇往直前",
    			"奔跑天路",
    			"思慕天家",
    			"我家乃在天",
    			"來到美地",
    			"榮歸天鄉",
    			"天城美景",
    			"天國的人",
    			"我家在天",
    			"十架領路",
    			"榮耀天國",
    			"安息在天家",
    			"羨慕福地",
    			"榮美福地",
    			"非金也非銀",
    			"靠主領回天家",
    			"天上快樂家",
    			"思慕天鄉",
    			"永遠的榮耀",
    			"天上安樂處",
    			"百合花",
    			"因信有盼望",
    			"在基督裡必復活",
    			"我必親見主面",
    			"思念主來",
    			"聖徒被提",
    			"我必當面見主",
    			"當我行完今生路",
    			"天父監察",
    			"為主發光",
    			"積少成多",
    			"八福頌",
    			"真教會美德",
    			"聖徒美德",
    			"力行主道",
    			"聖靈佳果",
    			"隨處發光",
    			"火煉精金",
    			"克制情慾",
    			"清心有福",
    			"選民靈歌",
    			"求主察看",
    			"順從聖靈",
    			"願成主旨",
    			"聽命有福",
    			"遵命有福",
    			"謹守十誡",
    			"義人有福",
    			"照主所願",
    			"要同耶穌一樣",
    			"聯屬耶穌",
    			"與主日近",
    			"主我一體",
    			"我屬耶穌",
    			"耶穌住在我心",
    			"來居我心，主耶穌！",
    			"求主同住",
    			"與主同樂",
    			"我生命的君王",
    			"主在門外等候",
    			"引我更親近",
    			"主！我願像你",
    			"求主密相契",
    			"懇求聖靈",
    			"聖靈權能",
    			"我要求聖靈",
    			"靈洗各人",
    			"從新得力",
    			"聖靈的洗",
    			"渴慕聖靈充滿",
    			"聖靈已來",
    			"方言寶貴",
    			"主今夜賜福",
    			"恩雨大降",
    			"儆醒祈禱",
    			"禁食禱告",
    			"恆切禱告",
    			"清晨頌主",
    			"晚禱感恩",
    			"與神靈交",
    			"耶穌恩友",
    			"求主垂憐",
    			"快告訴主耶穌",
    			"傳揚福音",
    			"聽主差遣",
    			"聽從主呼召",
    			"聞主呼召",
    			"到遙遠地方",
    			"不要懼怕",
    			"保惠師已經到",
    			"大喜信息",
    			"晚雨降臨(甲)",
    			"福音要傳遍(乙)",
    			"禾捆收回家",
    			"來聽福音",
    			"喜傳福音",
    			"主拯救",
    			"敞開恩門",
    			"廣傳福音",
    			"嘆未得人",
    			"努力工作",
    			"為主收莊稼",
    			"發出福音真光",
    			"開船入深海",
    			"傳佈救恩",
    			"為耶穌勞力",
    			"趕快工作",
    			"派任聖職",
    			"按立禮",
    			"洗罪泉源",
    			"贖罪妙恩",
    			"洗淨罪愆",
    			"我來就你",
    			"洗腳禮",
    			"記念主死(甲)",
    			"豈能讓主獨背十架?(乙)",
    			"為主我立何志？",
    			"聖徒婚禮",
    			"婚禮祝歌",
    			"祝新婚之樂",
    			"人生不長",
    			"安葬",
    			"天國來了",
    			"浪子回家",
    			"儆醒自責",
    			"悔改重生",
    			"回來罷！",
    			"天父接納我",
    			"新年祈望",
    			"年終感頌",
    			"一齊來歌頌",
    			"齊聚主前",
    			"這世界的光是耶穌",
    			"耶穌呼召",
    			"永世的君王",
    			"敬拜榮耀主",
    			"我救主已來到",
    			"安穩港口",
    			"敬拜基督新生王",
    			"天使歌唱",
    			"信徒齊來頌主",
    			"榮耀歸於天父",
    			"獻上千萬榮冠",
    			"慈愛的救主",
    			"救主耶穌是我至寶",
    			"歡唱詠不停",
    			"多認識耶穌",
    			"讚美真神創造主",
    			"天父我神",
    			"奇妙平安由神來",
    			"聖靈信實保惠師",
    			"真神大愛",
    			"欣逢聖日",
    			"耶穌，沙崙玫瑰",
    			"真希奇，我主的慈愛",
    			"耶穌是否仍然看顧我？",
    			"耶穌揀選我",
    			"祂拯救我",
    			"耶穌是我一切所有",
    			"奇妙的救主",
    			"讓主耶穌進入你心",
    			"你的光當照耀",
    			"愛拯救我",
    			"暴風雨中的避難所",
    			"深哉，深哉，耶穌的愛",
    			"耶穌溫柔慈聲呼喚",
    			"萬古磐石藏身所",
    			"祂是奇妙救主",
    			"救主正在等待",
    			"主比生命更寶貴",
    			"每一天",
    			"主藏我靈",
    			"在主十架下",
    			"只要信祂",
    			"平安永在我心",
    			"信心使我得勝",
    			"主耶和華是我牧者",
    			"基督活在我心",
    			"同心前往錫安",
    			"你心可有住處為主？",
    			"領我到髑髏地",
    			"求主擘生命餅",
    			"堅立在應許上",
    			"主話語深藏我心",
    			"救主受難",
    			"照主旨意行",
    			"祂看顧麻雀",
    			"快傳福音",
    			"在各各他",
    			"主幫助我們",
    			"面臨試煉時候",
    			"降百福甘霖",
    			"只要相信",
    			"求永恆君王前導",
    			"主呼召你",
    			"堅固磐石",
    			"主常常顧念我",
    			"信靠順服",
    			"轉眼仰望耶穌",
    			"我主是我生命標竿",
    			"我何等愛耶穌",
    			"我靈安穩",
    			"將有一天",
    			"我願效法耶穌",
    			"救贖",
    			"我得一友",
    			"求主對我述說",
    			"靠近耶穌慈懷",
    			"親近，更親近",
    			"主！我願更親近你",
    			"永不孤單",
    			"任主差派",
    			"聽！良牧慈聲",
    			"感謝神",
    			"向高處行",
    			"我要真誠",
    			"何不今日歸耶穌？",
    			"為主而活",
    			"主，我願做你門徒",
    			"我深願更像耶穌",
    			"須用工夫成聖",
    			"神的道路",
    			"任憑主旨意",
    			"讚美救主",
    			"你是否已禱告",
    			"要告訴耶穌",
    			"在花園裡",
    			"若主今日再臨",
    			"我可願作十架精兵？",
    			"再等不多時",
    			"美麗的禱告花園",
    			"寶貴禱告良辰",
    			"我們同心聚集",
    			"恩主與我同在",
    			"獻上至好的",
    			"你可情願？",
    			"耶穌領我回家",
    			"一切獻在壇上",
    			"因我得福",
    			"奉獻與你",
    			"請來赴宴",
    			"我錨堅固牢靠",
    			"對我述說耶穌故事",
    			"我王之事工",
    			"我屬我王",
    			"何等奇妙的救主",
    			"有一故事傳給萬邦",
    			"耶穌與我同行",
    			"我必親見榮耀主",
    			"我們聚集生命河邊",
    			"全備的愛",
    			"祂大能手扶持我",
    			"奇妙平安",
    			"在那榮耀國度",
    			"歌頌救贖恩主",
    			"我一生蒙救主引導",
    			"誰正守候在門外?",
    			"頌主創造美好",
    			"時刻交託主",
    			"在主愛中團契",
    			"我立下決心",
    			"神一路引領",
    			"榮耀永歸耶穌",
    			"耶穌聖名最甜美",
    			"恩典大過我罪愆",
    			"頌讚主聖名",
    			"高唱和散那",
    			"歡欣，主為君王",
    			"何能如此",
    			"吹響征戰號",
    			"藏身主懷",
    			"我願常見你",
    			"我是君王後嗣",
    			"以馬內利，懇求降臨",
    			"最美聖名",
    			"歸家",
    			"耶穌奇妙的救恩",
    			"你在哪裡？",
    			"約旦河畔",
    			"願主賜福保祐你",
    			"快拋救生索",
    			"哈利路亞，奇妙君王",
    			"當歡欣喜樂",
    			"先賢所信",
    			"到各山嶺去傳揚",
    			"讚美耶穌基督",
    			"主的應許",
    			"寶貴回憶"
    	};
    	
    	try {
    		FileOutputStream out = new FileOutputStream(file);
    		OutputStreamWriter sw = new OutputStreamWriter(out, "BIG5");
    		
    		sw.write("資料庫序列,編目,歌名,評等,編輯次數,熟悉度," +
    				"風格,場合,司琴難易度,司琴熟練度,作曲者,作詞者,歌譜," +
    				"歌詞,詩集,調性,節奏,經節,故事,詩歌事件\r\n");
    		
    		for(int i=0;i<serial.length;i++){
    			lineString = serial[i] +","+index[i]+","+title[i]+",0,0,熟悉度未知,"
    						+"尚無風格,尚無場合,難易度未知,熟悉度未知,作曲者未知," 
    						+"作詞者未知,尚無歌譜,尚無歌詞,詩集未知,調性未知,節奏未知," 
    						+"經節未知,尚無故事,尚無事件"
    						+"\r\n";
;
    			sw.write(lineString);  
    		}
    		sw.flush();     
    		sw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}	//END try
		
    }	//end createHymns.csv
	
	
}
